<template>
	<div>
		<el-row :gutter="10">
			<div v-for="(item, key) in options" :key="key">
				<XcFormItemInput v-bind="$attrs" v-if="['textarea','text','password',undefined].includes(item.type)" :options="item"
					v-model="formData[item.prop]" />
				<el-col :span="item.span || 22" v-if="item.type==='slot'">
					<el-form-item :label="item.label" :prop="item.prop" :labelWidth="item.labelWidth">
						<slot :name="item.name"/>
					</el-form-item>
				</el-col>
				<XcFormItemNumber v-bind="$attrs" v-if="['number'].includes(item.type)" :options="item"
					v-model="formData[item.prop]" />
				<XcFormItemSwitch v-bind="$attrs" v-if="['switch'].includes(item.type)" :options="item" v-model="formData[item.prop]" />
				<XcFormItemButton v-bind="$attrs" v-if="['button'].includes(item.type)" :options="item"
					v-model="formData[item.prop]" />
				<XcFormItemDatePicker v-bind="$attrs" v-if="['dates','date','datetime'].includes(item.type)" :options="item"
					v-model="formData[item.prop]" />
				<XcFormItemSelect v-bind="$attrs" v-if="item.type==='select'" :options="item" :list="vm[item.options]"
					v-model="formData[item.prop]" />
				<XcFormItemCascader v-bind="$attrs" v-if="item.type==='cascader'" :options="item" :list="vm[item.options]"
					v-model="formData[item.prop]" />
				<XcFormItemImg :path="item.path!==undefined?item.path:'path'" v-bind="$attrs" v-if="item.type==='img'"
					:options="item" v-model="formData[item.prop]" />
				<XcFormItemTimePicker v-bind="$attrs" v-if="item.type==='timePicker'" :options="item"
					v-model="formData[item.prop]" />
				<XcFormItemTimeSelect v-bind="$attrs" v-if="item.type==='timeSelect'" :options="item" :list="vm[item.options]"
					:pickOptions="{
          ...item.pickOptions,
          minTime: item.pickOptions.minTime?formData[item.pickOptions.minTime] :''
        }" v-model="formData[item.prop]" />
				<XcFormItemEditor v-bind="$attrs" v-if="item.type==='editor'" :options="item" v-model="formData[item.prop]" />
				<XcFormItemImgs v-bind="$attrs" v-if="item.type==='imgs'" :options="item" v-model="formData[item.prop]" />
				<XcFormItemDefault v-bind="$attrs" v-if="['default'].includes(item.type)" :options="item"
					v-model="formData[item.prop]" />
			</div>
			<slot />
		</el-row>
	</div>
</template>

<script>
	import {
		object
	} from "../utils/validate";
	export default {
		props: {
			form: String,
			options: Array,
		},
		created() {
			if (this.vm[this.form] == undefined) {
				// this.$toast("未定义formData");
			} else if (!object(this.vm[this.form])) {
				// this.$toast("formData应为object");
			}
			// console.log(	this.vm,this.vm.options);
		},
		computed: {
			formData() {
				return this.vm[this.form || 'formData'];
			},
			vm() {
				return this.vm;
			},
		},
		inject: ["vm"],
	};
</script>

<style>
</style>